package com.lagou.controller;

import com.lagou.service.ICodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/code")
public class ServiceCodeController {

    @Autowired
    private ICodeService codeService;

    /**
     * ⽣生成验证码并发送到对应邮箱，成功true，失败false
     *
     * @param email
     * @return
     */
    @GetMapping("/create/{email}")
    public Boolean create(@PathVariable("email") String email) {
        return codeService.create(email);
    }

    /**
     * 校验验证码是否正确， 0正确，1错误，2超时
     *
     * @param email
     * @param code
     * @return
     */
    @GetMapping("/validate/{email}/{code}")
    public String validate(@PathVariable("email") String email, @PathVariable("code") String code) {
        return codeService.validate(email, code);
    }
}
